#include "ScnsInclude.h"
#include "JctoInclude.h"
#include "init.h"
#include "hxPrintf.h"
#include <math.h>
#include <omp.h>

float diff[4][1000];

int main(int argc,char**argv,char**envp)
{
    init();
    JctoArgv jctoArgv;
    jctoArgvDecode(&jctoArgv,argc,argv,envp);
    jctoArgvSave(&jctoArgv,stdout);
    {
        for(float f=1e-6;f<=1e6;f*=10)
        {
            uint8 buf1[24];
            scnsBufferSetFloat16(buf1,0,sizeof buf1,f);
            const float d1=scnsBufferGetFloat16(buf1,0,sizeof buf1);
            hxPrintf("%f %f\n",f,d1);
        }
    }

#pragma omp parallel for
    for(uint64 k=0;k<=0XFFFFFFFF;++k)
    {
        uint32 i=k;
        float f=*((float*)(&i));
        if(scnsIsFiniteF(f))
        {
            uint8 buf1[24],buf2[24];
            scnsBufferSetFloat16(buf1,0,sizeof buf1,f);
            scnsBufferSetFloat24(buf2,0,sizeof buf1,f);
            const float d1=scnsBufferGetFloat16(buf1,0,sizeof buf1);
            const float d2=scnsBufferGetFloat24(buf2,0,sizeof buf2);
            diff[0][omp_get_thread_num()]=scnsMax(diff[0][omp_get_thread_num()],scnsAbs(f-d1));
            diff[1][omp_get_thread_num()]=scnsMax(diff[1][omp_get_thread_num()],scnsAbs((f-d1)/f));
            diff[2][omp_get_thread_num()]=scnsMax(diff[2][omp_get_thread_num()],scnsAbs(f-d2));
            diff[3][omp_get_thread_num()]=scnsMax(diff[3][omp_get_thread_num()],scnsAbs((f-d2)/f));
        }
    }

    for(int j=0;j<4;++j)
    {
        for(int i=0;i<1000;++i)
        {
            diff[j][0]=scnsMax(diff[j][0],diff[j][i]);
        }
        hxPrintf("diff[%d][0]=%f\n",j,diff[j][0]);
    }
    stop(0);
    return 0;
}